﻿Imports System.Drawing
Imports System.Web.UI.WebControls
Imports System.Web.UI.HtmlControls
Imports Camstar.WebClient.FormsBuilder.WebForm
Imports Camstar.WebClient.WebServicesProxy.InSiteWebServices
Imports System.IO
Imports Camstar.WebClient.WebConstants
Imports BusinessRule.IBusiness
Imports BusinessRule.DTO
Imports BusinessRule.BusinessFactory
Imports BusinessRule.Common

Partial Class DealFaultBillPrintForm
    Inherits System.Web.UI.Page

    Private oIBusiness As uLMSDealFaultBillIbusiness = uMESBusinessFactory.instance.GetuLMSdealFaultBillObject()
    Public strProductName As String
    Public htmlstr As String
    Public strHtmlTable As String
    Public Shared PrintType As String
    Public Shared strEName As String

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            If IsNothing(Session("PGDIDForPrint")) = True Then
                Try
                    Dim PGDID As String = Me.Request.Params("PGDID")
                    Session("PGDIDForPrint") = PGDID
                Catch ex As Exception

                End Try
            End If

            If IsNothing(Session("PGDIDForPrint")) = False Then
                PrintType = Me.Request.Params("type")
                Dim para As New Dictionary(Of String, String)
                para("PGDID") = Session("PGDIDForPrint")
                If para("PGDID").ToString = String.Empty Then
                    Response.Write("<script type='text/javascript'>alert('没有要打印的排故单');window.close();</script>")
                    Return
                Else
                    Dim PGDID As String = para("PGDID")
                    strHtmlTable = String.Empty
                    Dim idList() As String = PGDID.Split(",")
                    For Each id As String In idList
                        iniPate(id)
                    Next

                End If
            Else
                Response.Write("<script type='text/javascript'>alert('没有要打印的排故单');window.close();</script>")
                Return
            End If
        End If
    End Sub

    Private Sub iniPate(ByVal PGDID As String)
        Dim strHtmlTitle As String
        Dim strHtmlTableMain As String
        Dim strHtmlTableDetails As String

        Dim dic As New Dictionary(Of String, String)
        dic.Add("DealFaultBillID", PGDID)
        Dim PR As DataTable = oIBusiness.GetPGDataTable(dic)

        strHtmlTableMain = SetTableMain(PR)
        strHtmlTitle = SetTableTitle(Nothing)
        strHtmlTableDetails = SetTableDetail(Nothing)

        strHtmlTable += String.Format("{0}{1}{2}", strHtmlTitle, strHtmlTableMain, strHtmlTableDetails)
    End Sub

    Private Function SetTableMain(ByVal PR As DataTable) As String
        Dim dt As DataTable = PR
        Dim strId As String = Session("PGDIDForPrint")
        strEName = dt.Rows(0)("DealFaultbillname").ToString
        Dim strFamilyName As String = IIf(PrintType.Equals("1"), "", dt.Rows(0)("ENGINEFAMILY").ToString)
        'Dim strMachineName As String = dt.Rows(0)("containername").ToString '发动机号
        'Dim strComCName As String = dt.Rows(0)("comContainername").ToString '组合件号
        Dim strWorkhours As String = dt.Rows(0)("machineworkhours").ToString '工作时间
        Dim DEALFAULTSTATUS As String = dt.Rows(0)("DEALFAULTSTATUS").ToString '状态
        Dim strfaultdesc As String = dt.Rows(0)("faultdesc").ToString '故障情况
        Dim strBatch As String = dt.Rows(0)("PRODUCTANDBATCH").ToString() '组合件号/批次号
        If strBatch = "" Then
            strBatch = "/"
        End If
        Dim sbhtml As New StringBuilder

        sbhtml.AppendLine("<table id='head' width='100%'><tr><td style='width:100px'>" + IIf(PrintType.Equals("1"), "公开", "内部") + "</td><td style='text-align:right'>HF.131460W0195（V1.0）</td></tr></table>")
        sbhtml.AppendLine("<table id='Up' width='100%' border='1' cellspacing='0' cellpadding='0'> ")
        sbhtml.AppendLine("<tr>    <td  colspan='2' >编号</td> <td >" + strEName + "</td> ")
        sbhtml.AppendLine(" <td   >返回时间</td> <td   >" + dt.Rows(0)("returntime").ToString + "</td> </tr>")
        sbhtml.AppendLine("<tr>    <td   style='width:100px;'>型号</td>    <td  style='width:160px;'>" + strFamilyName + "</td> ")
        sbhtml.AppendLine(" <td rowspan='2'  style='width:200px;'> 排除故障工艺卡片</td> ")
        If String.IsNullOrWhiteSpace(DEALFAULTSTATUS) Then
            sbhtml.AppendLine("<td  style='width:160px;'>工作时间/状态</td>    <td  style='width:200px;'>" & IIf(strWorkhours = "", "/", strWorkhours) & " </td> ")
        Else
            sbhtml.AppendLine("<td  style='width:160px;'>工作时间/状态</td>    <td  style='width:200px;'>" & strWorkhours & "/" & DEALFAULTSTATUS & " </td> ")
        End If

        sbhtml.AppendLine(" </tr>  <tr>    <td>发动机号</td>    <td>" + dt.Rows(0)("ENGINENO").ToString + "</td>    <td>组合件号/批次号</td> ")
        sbhtml.AppendLine(" <td>" & strBatch & "</td>  </tr></table> ") 'dt.Rows(0)("PRODUCTNAME").ToString & "/" & dt.Rows(0)("PRODUCTBATCHNO").ToString
        sbhtml.AppendLine("<table id='Mid' width='100%' frame=vsides cellspacing='0'  cellpadding='0'> ")
        sbhtml.AppendLine("<tr>    <td colspan='7' style=' text-align:left'>故障情况:</td>      </tr> ")
        sbhtml.AppendLine(" <tr>    <td  colspan='7' style='height:100px'><div style='height:100%'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" + strfaultdesc + "</div></td>      </tr>  <tr class='Mid'>")
        sbhtml.AppendLine(" <td style='width:90px'>&nbsp;</td> ")
        sbhtml.AppendLine(" <td style='width:90px'>主管技术员:</td> <td style='width:220px;' > " + dt.Rows(0)("CREATEEMP").ToString + "&nbsp;&nbsp;&nbsp;&nbsp;" + Date.Parse(dt.Rows(0)("createdate").ToString()).ToString("yyyy-MM-dd") + "</td>")

        If dt.Rows(0).IsNull("Confirmtime") Then
            sbhtml.AppendLine("<td style='width:60px'>检验员:</td>    <td style='width:200px'>" + dt.Rows(0)("CONFIRMEMP").ToString + "&nbsp;&nbsp;&nbsp;&nbsp;" + "" + "</td> ")
        Else
            sbhtml.AppendLine("<td style='width:60px'>检验员:</td>    <td style='width:200px'>" + dt.Rows(0)("CONFIRMEMP").ToString + "&nbsp;&nbsp;&nbsp;&nbsp;" + Date.Parse(dt.Rows(0)("Confirmtime").ToString()).ToString("yyyy-MM-dd") + "</td> ")
        End If

        sbhtml.AppendLine(" <td style='width:100px'>顾客代表:</td>    <td style='width:200px;text-align: center;'>" + IIf(dt.Rows(0)("ISARMY").ToString.Equals("否"), "", "<img src='" + dt.Rows(0)("AUDITEMPLOYEENAME").ToString + "' />") + "</td>  </tr></table>")

        sbhtml.AppendLine("<table class='Down' width='100%' border='1' cellspacing='0' cellpadding='0'> ")
        sbhtml.AppendLine(" <tr>    <td  style='width:80px;'>工序号</td>    <td style='width:170px;'>排除方法</td> ")
        sbhtml.AppendLine("    <td  style='width:170px;'>排除情况</td>  ")
        sbhtml.AppendLine(" <td  style='width:100px;'>合格数</td> <td  style='width:100px;'>不合格数</td>")
        sbhtml.AppendLine("  <td  style='width:100px;'>工人</td> <td  style='width:100px;'>检验员</td>  </tr>")

        Dim RowCount As Integer = 5
        For i As Integer = 0 To RowCount - 1
            sbhtml.AppendLine(" <tr>    <td>&nbsp;</td>    <td>&nbsp;</td>    <td>&nbsp;</td>    <td>&nbsp;</td> ")
            sbhtml.AppendLine(" <td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td>  </tr>")
        Next

        sbhtml.AppendLine("</table> ")
        sbhtml.AppendLine("<table class='Bot' width='100%' border='1'; cellspacing='0' cellpadding='0'> ")
        sbhtml.AppendLine("  <tr>    <td style='width:50px'>编制</td>    <td style='width:70px'>&nbsp;</td>")
        sbhtml.AppendLine(" <td style='width:50px'>校对</td>    <td style='width:70px'>&nbsp;</td>")
        sbhtml.AppendLine(" <td style='width:50px'>审核</td>    <td style='width:70px'>&nbsp;</td>")
        sbhtml.AppendLine(" <td style='width:100px'>检验室主任</td>    <td style='width:100px'>&nbsp;</td> ")
        sbhtml.AppendLine("<td style='width:100px'>顾客代表</td>    <td style='width:100px'>" + IIf(String.IsNullOrWhiteSpace(dt.Rows(0)("RESULTAUDITEMPLOYEENAME").ToString), "", "<img src='" + dt.Rows(0)("RESULTAUDITEMPLOYEENAME").ToString + "' />") + "</td>  </tr></table> ")
        sbhtml.AppendLine("<table class='Bot' width='100%' cellspacing='0' cellpadding='0'> ")
        sbhtml.AppendFormat(" <tr>    <td class=barCode style='text-align:left;'>*{0}*</td></tr></table>", strEName)
        sbhtml.AppendLine("<div style='page-break-after:always;'></div>")
        SetTableMain = sbhtml.ToString()
    End Function

    Private Function SetTableDetail(ByVal PR As uMESProcessResult) As String
        SetTableDetail = String.Empty
    End Function

    Private Function SetTableTitle(ByVal PR As uMESProcessResult) As String
        Dim sbhtml As New StringBuilder
        SetTableTitle = sbhtml.ToString
    End Function
End Class
